package com.ruoyi.web.controller.inventory;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.InventoryDetails;
import com.ruoyi.system.service.IInventoryDetailsService;
import com.ruoyi.system.util.AbdulEmptyUtils;
import com.ruoyi.system.util.BaseResponse;
import com.ruoyi.system.util.StoreIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 入库明细 Controller
 *
 * @author ruoyi
 * @date 2025-06-04
 */
@Api(tags = "出入库明细管理")
@RestController
@RequestMapping("/inventory-details")
public class InventoryDetailsController extends BaseController {

    @Autowired
    private IInventoryDetailsService inventoryDetailsService;

    @Autowired
    private StoreIdUtils storeIdUtils;

    @ApiOperation("查询出入库明细列表")
    @PostMapping("/page")
    public BaseResponse<IPage<InventoryDetails>> page(@RequestBody InventoryDetails inventoryDetails) {
        LambdaQueryWrapper<InventoryDetails> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(InventoryDetails::getStoreId, storeIdUtils.getStoreId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(inventoryDetails.getProductManagementId()), InventoryDetails::getProductManagementId, inventoryDetails.getProductManagementId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(inventoryDetails.getWarehousingEntryId()), InventoryDetails::getWarehousingEntryId, inventoryDetails.getWarehousingEntryId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(inventoryDetails.getClassification()), InventoryDetails::getClassification, inventoryDetails.getClassification());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(inventoryDetails.getCategory()), InventoryDetails::getCategory, inventoryDetails.getCategory());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(inventoryDetails.getIsType()), InventoryDetails::getIsType, inventoryDetails.getIsType());
        wrapper.orderByDesc(InventoryDetails::getUpdateTime);
        return BaseResponse.success(inventoryDetailsService.page(new Page<>(inventoryDetails.getPageNum(), inventoryDetails.getPageSize()), wrapper));
    }
}
